﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dao;

namespace Web.Page
{
    public partial class ZL_CW_Add : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.lblTitle.Text = "新增仓位";
            }
        }


        /// <summary>
        /// 清空所有TextBox内容
        /// </summary>
        private void ClearControlsValue()
        {
            this.lbResult.Text = "";
            this.tbBH.Text = "";
            this.tbQU.Text = "";
            this.tbHANG.Text = "";
            this.tbCeng.Text = "";
            this.tbGe.Text = "";
            this.tbLIE.Text = "";
        }

        protected void btnSave0_Click(object sender, ImageClickEventArgs e)
        {
            this.lbResult.Text = "";

            ZL_CW entity = new ZL_CW()
            {
                ID = Guid.NewGuid(),
                BH = this.tbBH.Text.Trim(),
                QU = this.tbQU.Text.Trim(),
                HANG = this.tbHANG.Text.Trim(),
                CENG = this.tbCeng.Text.Trim(),
                GE = this.tbGe.Text.Trim(),
                LIE = this.tbLIE.Text.Trim()
            };

            string resultMessage = "";
            try
            {
                ZL_CW_Dao dao = new ZL_CW_Dao();

                if (dao.Exist(entity.BH))
                {
                    resultMessage = "同样编号的仓位已存在";
                    return;
                }

                int result = dao.Add(entity);

                if (result == 1)
                {
                    resultMessage = "保存成功";
                    ClearControlsValue();
                }
            }
            catch (Exception ex)
            {
                resultMessage = "保存失败" + ex.Message;
            }
            finally
            {
                this.lbResult.Text = resultMessage;
            }
        }

        protected void btnClear_Click(object sender, ImageClickEventArgs e)
        {
            ClearControlsValue();
        }

        protected void btnReturn_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("~/Page/ZL_CW_Query.aspx");
        }
    }
}